home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / parse.zip / PARSE.ASM next >
Assembly Source File  |  1986-01-06  |  3KB  |  117 lines

  1.     page 58,132
  2.     title
  3.     name 
  4.  
  5. comment    *
  6.  
  7.     This code will parse an command line and place all command line
  8.     arguments onto the stack and build "argc" and an "argv" array to
  9.     allow access to these arguments.
  10.     
  11.     6 Jan 85                Raymond Moon
  12.     
  13.     *
  14.     
  15.     .xlist
  16.     include \MASM\EQUATES.H            ; Include Equates header file
  17.     .list
  18.     
  19.     if1
  20.     include \MASM\MACRO.H            ; Include Macro header file
  21.     endif
  22.  
  23. GRP    group    CSEG,DSEG            ; All segments in same segment
  24.     assume    cs:GRP,ds:GRP,es:GRP,ss:GRP
  25.     
  26.     subttl Data Segments
  27.     page
  28.  
  29.     subttl  Code Segment
  30.     page
  31. CSEG    segment para public 'CODE'
  32.  
  33. ;----------------------------  
  34. ;    Define external procedures
  35.  
  36.     extrn CLS:near,ISDOS2:near
  37.  
  38. ;-----------------------------
  39. ;    Define all procedures as public for debugging
  40.  
  41.     public MAIN
  42.  
  43. ;-----------------------------
  44. ;    Define Command Line arguments located in the PSP
  45.  
  46.     org     80h
  47.     PARM_LEN db     ?
  48.     PARMS   db      127 dup(?)
  49.  
  50. ;-----------------------------
  51. ;    MAIN procedure parses the Command Line 
  52.  
  53.     org    100h            ; .COM file format
  54. MAIN    proc    far
  55.     push    pDOS_ERR        ; Pass addr of DOS_ERR
  56.     call    ISDOS2            ; Check to see if DOS is 2.0+ 
  57.     add    sp,2            ; Reset SP
  58.     cmp    PARM_LEN,0        ; Are there any Command Line arguments
  59.     jne    MN1            ; Yes, process them
  60.     call    MENU            ; No, go to Menu 
  61. MN1:    xor    cx,cx            ; Null CX
  62.     push    cx            ; This ensures last *argv ends in NUL
  63.     mov    cl,PARM_LEN        ; Get # of bytes in Command Line
  64.     inc    cl            ; Increment CL to ensure round up
  65.     and    cx,0feh            ; Force an even count
  66.     mov    ax,sp            ; Get SP  
  67.     mov    bp,sp            ; Set BP to last byte of Cmd Ln
  68.     sub    ax,cx            ; Subtract PARM_LEN
  69.     mov    sp,ax            ; Reset SP, room on Stack
  70.     lea    si,PARMS        ; Load source addr in SI
  71.     mov    di,sp            ; Load destin addr in DI
  72.     cld                ; Ensure Direction Flag is up
  73.     rep    movsb            ; Move Command Line onto the Stack
  74.  
  75. ;-----------------------------
  76. ;    Convert all blanks in the Command Line to Nul
  77.  
  78.     mov    bx,bp            ; BX points to last byte of Cmd Ln
  79. MN2:    mov    al,[bx]            ; Get byte
  80.     cmp    al,BLNK            ; Is it a blank?
  81.     ja    MN3            ; No, go set up to get another
  82.     xor    al,al            ; Nul AX
  83.     mov    [bx],al            ; Store Nul in [BX]
  84. MN3:    dec    bx            ; BX point to next byte
  85.     cmp    bx,sp            ; Are we through yet?
  86.     jnb    MN2            ; No, go one mo' 'gin
  87.                     
  88. ;-----------------------------
  89. ;    Build *argv[].  argc kept in CX.  DX used as IN_WORD flag
  90.  
  91.     xor    cx,cx            ; Set CX (argc) to 0
  92.     xor    dx,dx            ; Set DX to NOT_INWORD
  93.     mov    bx,bp            ; BX point to last byte
  94.     mov    bp,sp            ; BP now points to Top of Stack
  95. MN4:    mov    al,[bx]            ; Get byte
  96.     cmp    al,0            ; Is it Nul?
  97.     jne    MN5            ; No, it is a char
  98.     cmp    dx,0            ; Was the last byte not a char?
  99.     je    MN6            ; Yes, go on with the processing
  100.     xor    dx,dx            ; No, it was a char.  Clear INWORD.
  101.     inc    cx            ; Increment argc
  102.     inc    bx            ; BX points to Cmd Ln arg
  103.     push    bx            ; Push addr onto stack
  104.     dec    bx            ; Reset BX
  105.     jmp    short MN6        ; Go set up for another byte
  106. MN5:    inc    dx            ; Set DX to INWORD     
  107. MN6:    dec    bx            ; BX point to next byte
  108.     cmp    bx,bp            ; Are we at the 1st byte yet?
  109.     jnb    MN4            ; No, go process another
  110.  
  111. ;-----------------------------
  112. ;    Set up for and call ?
  113.  
  114.     push    cx            ; Push ARGC onto stack
  115.     call    CMDLN            ; Call Cmd Ln processor
  116. MAIN    endp
  117.